package com.kitty.game.mail.facade;


import com.kitty.game.role.model.Role;
import com.kitty.common.utils.SpringUtils;
import com.kitty.game.mail.message.ReqMail;
import org.springframework.stereotype.Controller;
import com.kitty.mina.annotation.RequestMapping;
import com.kitty.mina.cache.SessionUtils;
import com.kitty.game.mail.service.MailService;
import org.apache.mina.core.session.IoSession;

@Controller
public class MailController {


    @RequestMapping
    public void openMail(IoSession session, ReqMail reqMail) {
        //操作类型0是打开未读邮件 1是领取邮件附件 2是删除邮件
        MailService mailService = SpringUtils.getBean(MailService.class);
        Role role = SessionUtils.getRoleBySession(session);
        if (role == null) {
            return;
        }
        if (reqMail.getOperate() == 0) {//打开邮件
            mailService.openMail(role, reqMail.getMailId());
//            logger.error("打开邮件=={}=={}",role.getName(),reqMail.getMailId());
        } else if (reqMail.getOperate() == 1) {//领取邮件附件
            mailService.getMailItem(role, reqMail.getMailId());
//            logger.error("邮件领取附件=={}=={}",role.getName(),reqMail.getMailId());
        } else if (reqMail.getOperate() == 2) {//删除邮件
            mailService.removeMail(role, reqMail.getMailId());
//            logger.error("删除邮件=={}=={}",role.getName(),reqMail.getMailId());
        }else if (reqMail.getOperate() == 3) {
            mailService.getAllMailItem(role);
        }
        role.save();
    }
}
